<?php
/**
 * Joomla! 1.5 component NS Pro
 *
 * @version $Id: nspro.php 2009-04-28 01:47:12 svn $
 * @author Christopher Mavros
 * @package Joomla
 * @subpackage NS Pro
 * @license GNU/GPL
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');

class NsproModelNspro extends JModel {

    function __construct()
    {
        parent::__construct();

        $array = JRequest::getVar('cid',  0, '', 'array');
        $this->setId((int)$array[0]);
    }

    /**
     * Method to set the nssubs identifier
     *
     * @access  public
     * @param   int NsSubs identifier
     * @return  void
     */
    function setId($id)
    {
        // Set id and wipe data
        $this->_id      = $id;
        $this->_data    = null;
    }

    function getSub()
    {
        $db =& JFactory::getDBO();
        // Load the data
        if (empty( $this->_data )) {
            $query = ' SELECT * FROM `#__nspro_subs` '.
                    '  WHERE `id` = '.$this->_id;
            $db->setQuery( $query );
            $this->_data = $db->loadObject();
        }
        if (!$this->_data) {
            $this->_data = new stdClass();
            $this->_data->id = 0;
            $this->_data->name  = null;
            $this->_data->email = null;
            $this->_data->notes = null;
            $this->_data->datetime = null;
            $this->_data->confirmed = false;
            $this->_data->mailing_lists = null;            
        }
        return $this->_data;
    }

    function getSubs($limit, $limitstart) {
        $db =& JFactory::getDBO();

        $query = 'SELECT * FROM `#__nspro_subs`';

        $subs = $this->_getList( $query , $limitstart, $limit);

        return $subs;
    }

    function getSubsCount() {
        $db =& JFactory::getDBO();

        $query = 'SELECT COUNT(*) FROM `#__nspro_subs`';

        $db->setQuery( $query );
        $sCount = $db->loadResult();

        return $sCount;
    }
}
?>